package com.song.guli.service.statistics.task;

import com.song.guli.service.statistics.service.DailyService;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author 宋超
 * HP - the login name of the current user.
 * 2021/6/10 - the current system date.
 * 10:13 - the current system time.
 *
 * 在线生成cron表达式
 * http://cron.qqe2.com/
 */
@Component
@Slf4j
public class ScheduledTask {
    @Autowired
    private DailyService dailyService;

    @Scheduled(cron = "0 0 1 * * ?") //注意只支持6位表达式
    public void taskGenarateStatisticsData() {
        //获取上一天的日期
        String day = new DateTime().minusDays(1).toString("yyyy-MM-dd");
        dailyService.createStatisticsByDay(day);
        log.info("taskGenarateStatisticsData 统计完毕");
    }
}
